//
//  WeightViewController.m
//  Cycling
//
//  Created by 迟国强 on 2023/3/12.
//

#import "WeightViewController.h"

@interface WeightViewController ()
@property (nonatomic, strong) UITextField *weightF;
@end

@implementation WeightViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];

}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];

}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = CycLocalizedString(@"Weight", @"");
    self.view.backgroundColor = rgb(248, 248, 248);
    [self configUI];
    // Do any additional setup after loading the view.
}

- (void)configUI {
    
    UILabel *weightL = [[UILabel alloc] init];
    weightL.text = CycLocalizedString(@"Edit weight", @"修改体重");
    weightL.textColor = rgb(48, 48, 48);
    weightL.textAlignment = NSTextAlignmentCenter;
    weightL.font = [UIFont systemFontOfSize:24];
    [self.view addSubview:weightL];
    [weightL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(22);
        make.top.equalTo(self.view.mas_top).offset(30 + NavigationBarHeight);
    }];
    
    UILabel *weightUnitL = [[UILabel alloc] init];
    weightUnitL.text = CycLocalizedString(@"Unit:lbs", @"单位:lbs");
    weightUnitL.textColor = rgb(48, 48, 48);
    weightUnitL.textAlignment = NSTextAlignmentCenter;
    weightUnitL.font = [UIFont systemFontOfSize:24];
    [self.view addSubview:weightUnitL];
    [weightUnitL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(-22);
        make.centerY.equalTo(weightL.mas_centerY);
    }];
    
    UITextField *weightF = [[UITextField alloc] init];
    weightF.placeholder = CycLocalizedString(@"Input weight", @"请输入体重");
    weightF.keyboardType = UIKeyboardTypeDefault;
    weightF.layer.cornerRadius = 8;
    weightF.layer.masksToBounds = YES;
    weightF.textColor = rgbHex(0xA6A6A6,1.0);
    weightF.backgroundColor = UIColor.whiteColor;
    weightF.clearButtonMode = UITextFieldViewModeWhileEditing;
    weightF.borderStyle = UITextBorderStyleNone;
    [self.view addSubview:weightF];
    self.weightF = weightF;
    [weightF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(22);
        make.top.equalTo(weightL.mas_bottom).offset(7);
        make.right.equalTo(self.view.mas_right).offset(-22);
        make.height.offset(50);
    }];
    
    
    UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [doneBtn setTitle:CycLocalizedString(@"Finish", @"") forState:UIControlStateNormal];
    [doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [doneBtn setBackgroundImage:[UIImage imageNamed:@"btn_login"] forState:UIControlStateNormal];
    doneBtn.titleLabel.font = [UIFont systemFontOfSize:24];
    [doneBtn addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:doneBtn];
    [doneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(30);
        make.right.equalTo(self.view.mas_right).offset(-30);
        make.top.equalTo(weightF.mas_bottom).offset(32);
        make.height.offset(62);
    }];
    
}

- (void)done {
    self.block(self.weightF.text);
    [self.navigationController popViewControllerAnimated:YES];
}

@end
